Skip to content

SliceIdentityProxyModel

Sub classes

Name Children Inherits
SliceDisplayTextProxyModel
prettyqt.itemmodels.proxies.slicedisplaytextproxymodel
Proxy model to convert and format non-str values for the DisplayRole.
    SliceChangeIconSizeProxyModel
    prettyqt.itemmodels.proxies.slicechangeiconsizeproxymodel
    Proxy model which changes the icon size of the Decoration role.
      SliceFilterProxyModel
      prettyqt.itemmodels.proxies.slicefilterproxymodel
      Proxy model to filter an item view based on python slicing syntax.
        SliceCheckableProxyModel
        prettyqt.itemmodels.proxies.slicecheckableproxymodel
        Proxy model to make a model checkable.
          SliceCheckableTreeProxyModel
          prettyqt.itemmodels.proxies.slicecheckableproxymodel
          Proxy model to make a tree model checkable.
            SliceAppearanceProxyModel
            prettyqt.itemmodels.proxies.sliceappearanceproxymodel
              SliceChangeFlagsProxyModel
              prettyqt.itemmodels.proxies.slicechangeflagsproxymodel
              Proxy model to selectively change the ItemFlags of the source model.
                SliceColorValuesProxyModel
                prettyqt.itemmodels.proxies.slicecolorvaluesproxymodel
                Model to color cells of a numerical table based on their value.
                  SliceColorCategoriesProxyModel
                  prettyqt.itemmodels.proxies.slicecolorcategoriesproxymodel
                  Proxy model to apply coloring to categories.
                    SliceValueTransformationProxyModel
                    prettyqt.itemmodels.proxies.slicevaluetransformationproxymodel
                    A proxy model which transforms cell contents based on a Callable.
                      SliceHighlightCurrentProxyModel
                      prettyqt.itemmodels.proxies.slicehighlightcurrentproxymodel
                      Proxy model which highlights all cells with same data as current index.
                        SliceMapRoleProxyModel
                        prettyqt.itemmodels.proxies.slicemaproleproxymodel
                        Proxy model for mapping one role to another.
                          SliceToMarkdownProxyModel
                          prettyqt.itemmodels.proxies.slicetomarkdownproxymodel
                          Proxy model which transforms cell contents to markdown.

                            Base classes

                            Name Children Inherits
                            IdentityProxyModel
                            prettyqt.core.identityproxymodel
                            Proxies its source model unmodified.

                            â‹” Inheritance diagram

                            graph TD
                              4214724289["itemmodels.SliceIdentityProxyModel"]
                              527136029["core.IdentityProxyModel"]
                              2431222121["core.AbstractProxyModelMixin"]
                              3882849576["core.AbstractItemModelMixin"]
                              3227531497["core.ObjectMixin"]
                              2751680898["builtins.object"]
                              3668892142["QtCore.QIdentityProxyModel"]
                              3989152870["QtCore.QAbstractProxyModel"]
                              1898060022["QtCore.QAbstractItemModel"]
                              3984060476["QtCore.QObject"]
                              37984305["Shiboken.Object"]
                              527136029 --> 4214724289
                              2431222121 --> 527136029
                              3882849576 --> 2431222121
                              3227531497 --> 3882849576
                              2751680898 --> 3227531497
                              3668892142 --> 527136029
                              3989152870 --> 3668892142
                              1898060022 --> 3989152870
                              3984060476 --> 1898060022
                              37984305 --> 3984060476
                              2751680898 --> 37984305

                            🛈 DocStrings

                            Bases: IdentityProxyModel

                            Base model for slice proxy models.

                            By itself, this proxy does nothing. It just provides all needed helper functions to deal with slices. indexer_contains should be just by subclasses in order to check whether the proxy should be applied.

                            Source code in prettyqt/itemmodels/proxies/sliceidentityproxymodel.py
                            class SliceIdentityProxyModel(core.IdentityProxyModel):
                                """Base model for slice proxy models.
                            
                                By itself, this proxy does nothing.
                                It just provides all needed helper functions to deal with slices.
                                `indexer_contains` should be just by subclasses in order to check whether the proxy
                                should be applied.
                                """
                            
                                def __init__(self, indexer=None, **kwargs):
                                    super().__init__(**kwargs)
                                    self._indexer = (slice(None), slice(None))
                                    self.set_indexer(indexer)
                            
                                def indexer_contains(self, index: core.ModelIndex | tuple[int, int]) -> bool:
                                    """Check whether given ModelIndex is included in our Indexer."""
                                    if isinstance(index, core.ModelIndex):
                                        parent = self.mapToSource(index.parent()) if index.isValid() else None
                                        row, column = index.row(), index.column()
                                    else:
                                        parent = None
                                        row, column = index
                                    return row in self.get_row_range(parent) and column in self.get_column_range()
                            
                                def update_slice_boundaries(self, sl: slice, count: int) -> slice:
                                    """Update slice boundaries by resolving negative indexes."""
                                    return slice(*sl.indices(count))
                            
                                def set_indexer(self, indexer):
                                    """Takes basically anything which is common to use for __getitem__."""
                                    match indexer:
                                        case None:
                                            self._indexer = (slice(None), slice(None))
                                        case int() as column:
                                            self.set_column_slice(column)
                                        case slice() as col_slice:
                                            self._indexer = (col_slice, slice(None))
                                        case row_slice, col_slice:
                                            self.set_column_slice(col_slice)
                                            self.set_row_slice(row_slice)
                                        case _:
                                            raise TypeError(indexer)
                            
                                def get_column_slice(self) -> slice:
                                    match self._indexer:
                                        case None | (_, None):
                                            return slice(None)
                                        case (_, slice() as col_slice):
                                            return col_slice
                                        case _:
                                            raise TypeError(self._indexer)
                            
                                def get_row_slice(self) -> slice:
                                    match self._indexer:
                                        case None | (None, _):
                                            return slice(None)
                                        case (slice() as row_slice, _):
                                            return row_slice
                                        case _:
                                            raise TypeError(self._indexer)
                            
                                def set_column_slice(
                                    self, value: slice | int | tuple[int | None, int | None, int | None] | None
                                ):
                                    """Throw anything at this method in order to set the column slice."""
                                    match value:
                                        case slice() as col_slice:
                                            sl = col_slice
                                        case int() as col:
                                            sl = slice(col, col + 1)
                                        case None:
                                            sl = slice(None)
                                        case (
                                            int() | None as start,
                                            int() | None as stop,
                                            int() | None as step,
                                        ):
                                            sl = slice(start, stop, step)
                                        case _:
                                            raise TypeError(value)
                                    self._indexer = (self.get_row_slice(), sl)
                            
                                def set_row_slice(
                                    self, value: slice | int | tuple[int | None, int | None, int | None] | None
                                ):
                                    """Throw anything at this method in order to set the row slice."""
                                    match value:
                                        case slice() as row_slice:
                                            sl = row_slice
                                        case int() as row:
                                            sl = slice(row, row + 1)
                                        case None:
                                            sl = slice(None)
                                        case (
                                            int() | None as start,
                                            int() | None as stop,
                                            int() | None as step,
                                        ):
                                            sl = slice(start, stop, step)
                                        case _:
                                            raise TypeError(value)
                                    self._indexer = (sl, self.get_column_slice())
                            
                                def get_row_range(self, parent: core.ModelIndex | None = None) -> range:
                                    """Return a range for the row slice with valid start / stop / step values.
                            
                                    Arguments:
                                        parent: source parent index to get the range for (default: root)
                                    """
                                    source = self.sourceModel()
                                    row_count = 0 if source is None else source.rowCount(parent or core.ModelIndex())
                                    return range(*self.get_row_slice().indices(row_count))
                            
                                def get_column_range(self) -> range:
                                    """Return a range for the column slice with valid start / stop / step values."""
                                    source = self.sourceModel()
                                    col_count = 0 if source is None else source.columnCount()
                                    return range(*self.get_column_slice().indices(col_count))
                            
                                def position_in_column_slice(self, col: int) -> int:
                                    """Can be interpreted as slice.index(col) if slice would be a list."""
                                    return self.get_column_range().index(col)
                            
                                def position_in_row_slice(
                                    self, row: int, parent: core.ModelIndex | None = None
                                ) -> int:
                                    """Can be interpreted as slice.index(row) if slice would be a list."""
                                    return self.get_row_range(parent).index(row)
                            
                                # The Qt typesystems dont like slices (or ranges / tuples)
                                # seems what works is to throw tuples at a QtProperty declared as list.
                                # otherwise change this to list getters/setters.
                            
                                def get_column_tuple(self) -> tuple[int | None, int | None, int | None]:
                                    """Get tuple representation of the column slice."""
                                    sl = self.get_column_slice()
                                    return (sl.start, sl.stop, sl.step)
                            
                                def get_row_tuple(self) -> tuple[int | None, int | None, int | None]:
                                    """Get tuple representation of the row slice."""
                                    sl = self.get_row_slice()
                                    return (sl.start, sl.stop, sl.step)
                            
                                column_slice = core.Property(
                                    list,
                                    get_column_tuple,
                                    set_column_slice,
                                    doc="Column slice to include for the proxy",
                                )
                                row_slice = core.Property(
                                    list,
                                    get_row_tuple,
                                    set_column_slice,
                                    doc="Row slice to include for the proxy",
                                )
                            

                            get_column_range() -> range

                            Return a range for the column slice with valid start / stop / step values.

                            Source code in prettyqt/itemmodels/proxies/sliceidentityproxymodel.py
                            def get_column_range(self) -> range:
                                """Return a range for the column slice with valid start / stop / step values."""
                                source = self.sourceModel()
                                col_count = 0 if source is None else source.columnCount()
                                return range(*self.get_column_slice().indices(col_count))
                            

                            get_column_tuple() -> tuple[int | None, int | None, int | None]

                            Get tuple representation of the column slice.

                            Source code in prettyqt/itemmodels/proxies/sliceidentityproxymodel.py
                            def get_column_tuple(self) -> tuple[int | None, int | None, int | None]:
                                """Get tuple representation of the column slice."""
                                sl = self.get_column_slice()
                                return (sl.start, sl.stop, sl.step)
                            

                            get_row_range(parent: core.ModelIndex | None = None) -> range

                            Return a range for the row slice with valid start / stop / step values.

                            Parameters:

                            Name Type Description Default
                            parent ModelIndex | None

                            source parent index to get the range for (default: root)

                            None
                            Source code in prettyqt/itemmodels/proxies/sliceidentityproxymodel.py
                            def get_row_range(self, parent: core.ModelIndex | None = None) -> range:
                                """Return a range for the row slice with valid start / stop / step values.
                            
                                Arguments:
                                    parent: source parent index to get the range for (default: root)
                                """
                                source = self.sourceModel()
                                row_count = 0 if source is None else source.rowCount(parent or core.ModelIndex())
                                return range(*self.get_row_slice().indices(row_count))
                            

                            get_row_tuple() -> tuple[int | None, int | None, int | None]

                            Get tuple representation of the row slice.

                            Source code in prettyqt/itemmodels/proxies/sliceidentityproxymodel.py
                            def get_row_tuple(self) -> tuple[int | None, int | None, int | None]:
                                """Get tuple representation of the row slice."""
                                sl = self.get_row_slice()
                                return (sl.start, sl.stop, sl.step)
                            

                            indexer_contains(index: core.ModelIndex | tuple[int, int]) -> bool

                            Check whether given ModelIndex is included in our Indexer.

                            Source code in prettyqt/itemmodels/proxies/sliceidentityproxymodel.py
                            def indexer_contains(self, index: core.ModelIndex | tuple[int, int]) -> bool:
                                """Check whether given ModelIndex is included in our Indexer."""
                                if isinstance(index, core.ModelIndex):
                                    parent = self.mapToSource(index.parent()) if index.isValid() else None
                                    row, column = index.row(), index.column()
                                else:
                                    parent = None
                                    row, column = index
                                return row in self.get_row_range(parent) and column in self.get_column_range()
                            

                            position_in_column_slice(col: int) -> int

                            Can be interpreted as slice.index(col) if slice would be a list.

                            Source code in prettyqt/itemmodels/proxies/sliceidentityproxymodel.py
                            def position_in_column_slice(self, col: int) -> int:
                                """Can be interpreted as slice.index(col) if slice would be a list."""
                                return self.get_column_range().index(col)
                            

                            position_in_row_slice(row: int, parent: core.ModelIndex | None = None) -> int

                            Can be interpreted as slice.index(row) if slice would be a list.

                            Source code in prettyqt/itemmodels/proxies/sliceidentityproxymodel.py
                            def position_in_row_slice(
                                self, row: int, parent: core.ModelIndex | None = None
                            ) -> int:
                                """Can be interpreted as slice.index(row) if slice would be a list."""
                                return self.get_row_range(parent).index(row)
                            

                            set_column_slice(value: slice | int | tuple[int | None, int | None, int | None] | None)

                            Throw anything at this method in order to set the column slice.

                            Source code in prettyqt/itemmodels/proxies/sliceidentityproxymodel.py
                            def set_column_slice(
                                self, value: slice | int | tuple[int | None, int | None, int | None] | None
                            ):
                                """Throw anything at this method in order to set the column slice."""
                                match value:
                                    case slice() as col_slice:
                                        sl = col_slice
                                    case int() as col:
                                        sl = slice(col, col + 1)
                                    case None:
                                        sl = slice(None)
                                    case (
                                        int() | None as start,
                                        int() | None as stop,
                                        int() | None as step,
                                    ):
                                        sl = slice(start, stop, step)
                                    case _:
                                        raise TypeError(value)
                                self._indexer = (self.get_row_slice(), sl)
                            

                            set_indexer(indexer)

                            Takes basically anything which is common to use for getitem.

                            Source code in prettyqt/itemmodels/proxies/sliceidentityproxymodel.py
                            def set_indexer(self, indexer):
                                """Takes basically anything which is common to use for __getitem__."""
                                match indexer:
                                    case None:
                                        self._indexer = (slice(None), slice(None))
                                    case int() as column:
                                        self.set_column_slice(column)
                                    case slice() as col_slice:
                                        self._indexer = (col_slice, slice(None))
                                    case row_slice, col_slice:
                                        self.set_column_slice(col_slice)
                                        self.set_row_slice(row_slice)
                                    case _:
                                        raise TypeError(indexer)
                            

                            set_row_slice(value: slice | int | tuple[int | None, int | None, int | None] | None)

                            Throw anything at this method in order to set the row slice.

                            Source code in prettyqt/itemmodels/proxies/sliceidentityproxymodel.py
                            def set_row_slice(
                                self, value: slice | int | tuple[int | None, int | None, int | None] | None
                            ):
                                """Throw anything at this method in order to set the row slice."""
                                match value:
                                    case slice() as row_slice:
                                        sl = row_slice
                                    case int() as row:
                                        sl = slice(row, row + 1)
                                    case None:
                                        sl = slice(None)
                                    case (
                                        int() | None as start,
                                        int() | None as stop,
                                        int() | None as step,
                                    ):
                                        sl = slice(start, stop, step)
                                    case _:
                                        raise TypeError(value)
                                self._indexer = (sl, self.get_column_slice())
                            

                            update_slice_boundaries(sl: slice, count: int) -> slice

                            Update slice boundaries by resolving negative indexes.

                            Source code in prettyqt/itemmodels/proxies/sliceidentityproxymodel.py
                            def update_slice_boundaries(self, sl: slice, count: int) -> slice:
                                """Update slice boundaries by resolving negative indexes."""
                                return slice(*sl.indices(count))
                            

                            :fa-brands-github: Show source on GitHub